package com.bloom.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.bloom.entity.DisplayInfo;

public class StaticDataDao {

	@PersistenceContext
	private EntityManager entityManager;

	public List<DisplayInfo> getTransportModes() {
		Query query = entityManager
				.createQuery("from DisplayInfo as di where di.refCode = 1");
		List<DisplayInfo> resultList = query.getResultList();
		return resultList;
	}

	// TODO: Merge country-city into one method
	public List<DisplayInfo> getCountryList() {
		Query query = entityManager
				.createQuery("from DisplayInfo as di where di.refCode = 2 and di.relatedId = 0");
		List<DisplayInfo> resultList = query.getResultList();
		return resultList;
	}

	public List<DisplayInfo> getCityList() {
		Query query = entityManager
				.createQuery("from DisplayInfo as di where di.refCode = 2 and di.relatedId != 0");
		List<DisplayInfo> resultList = query.getResultList();
		return resultList;
	}

	public DisplayInfo getDisplayInfo(int id) {
		Query query = entityManager
				.createQuery("from DisplayInfo as di where di.id = :id");
		query.setParameter("id", id);
		List<DisplayInfo> resultList = query.getResultList();
		DisplayInfo displayInfo = null;
		if (resultList != null && !resultList.isEmpty()) {
			displayInfo = resultList.get(0);
		}
		return displayInfo;
	}
}
